fix(agent): skip empty switch conditions#15691
Conversation
📝 WalkthroughWalkthroughSwitch._invoke now checks ChangesSwitch empty condition evaluation fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/unit_test/agent/component/test_switch.py`:
- Around line 26-41: Add the appropriate pytest priority marker to the test
function test_switch_empty_condition_falls_through_to_else (and the other test
in the same file referenced at lines 44-59) by decorating each test with
`@pytest.mark.p1` (or the correct priority per test suite rules); ensure pytest is
imported at the top of test_switch.py (add "import pytest" if absent) so the
decorator resolves.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d9194356-7683-4e84-b082-8356e0aed2d7
📒 Files selected for processing (2)
agent/component/switch.pytest/unit_test/agent/component/test_switch.py
| def test_switch_empty_condition_falls_through_to_else(): | ||
| param = SwitchParam() | ||
| param.conditions = [ | ||
| { | ||
| "logical_operator": "and", | ||
| "items": [{"cpn_id": "", "operator": "=", "value": "yes"}], | ||
| "to": ["case_target"], | ||
| } | ||
| ] | ||
| param.end_cpn_ids = ["else_target"] | ||
|
|
||
| cpn = _switch(param) | ||
| cpn._invoke() | ||
|
|
||
| assert cpn.output("_next") == ["else_target"] | ||
| assert cpn.output("next") == ["else_target"] |
There was a problem hiding this comment.
Add pytest priority markers to test functions.
Both test functions are missing priority markers (@pytest.mark.p1, @pytest.mark.p2, or @pytest.mark.p3). As per coding guidelines, all tests in test/**/*.py should use pytest priority markers.
📝 Proposed fix to add priority markers
+import pytest
+
from agent.component.switch import Switch, SwitchParam
class _Canvas:+@pytest.mark.p1
def test_switch_empty_condition_falls_through_to_else():
param = SwitchParam()+@pytest.mark.p1
def test_switch_non_empty_and_condition_still_matches():
param = SwitchParam()Also applies to: 44-59
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/unit_test/agent/component/test_switch.py` around lines 26 - 41, Add the
appropriate pytest priority marker to the test function
test_switch_empty_condition_falls_through_to_else (and the other test in the
same file referenced at lines 44-59) by decorating each test with
`@pytest.mark.p1` (or the correct priority per test suite rules); ensure pytest is
imported at the top of test_switch.py (add "import pytest" if absent) so the
decorator resolves.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15691 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What
Switchignore conditions that have no evaluable itemscpn_iditems falling through to the else branchandcondition behavior coveredFixes #15643.
Verified
python -m py_compile agent\component\switch.py test\unit_test\agent\component\test_switch.pypython -m pytest test\unit_test\agent\component\test_switch.py -q->2 passedpython -m ruff check agent\component\switch.py test\unit_test\agent\component\test_switch.pygit diff --checkI also checked
python -m ruff format --checkon the touched files. It would reformat pre-existing style inagent/component/switch.pybeyond this bug fix, so I kept the patch scoped instead of reformatting the whole file.